package com.lwj.springbootvue.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.lwj.springbootvue.model.Classe;
import com.lwj.springbootvue.model.Student;
import com.lwj.springbootvue.model.vo.StudentVo;
import com.lwj.springbootvue.response.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.lwj.springbootvue.service.IStudentService;


/**
 * 学生Controller
 * 
 * @author king
 * @date 2024-12-25
 */

@RestController
@RequestMapping("/student")
public class StudentController
{
    @Autowired
    private IStudentService studentService;






    /**
     * 查询学生列表
     */

    @GetMapping("/list")
    public Result list(Student student)
    {
        PageInfo<StudentVo> studentVoPageInfo = studentService.selectStudentVoList(student);
        List<StudentVo> studentVosList = studentVoPageInfo.getList();
        return Result.success(studentVosList).put("total",studentVoPageInfo.getTotal());
    }


    /**
     * 获取学生详细信息
     */

    @GetMapping(value = "/{sid}")
    public Result getInfo(@PathVariable("sid") Long sid)
    {
        return Result.success(studentService.selectStudentBySid(sid));
    }

    /**
     * 新增学生
     */

    @PostMapping
    public Result add(@RequestBody Student student)
    {
        return Result.success(studentService.insertStudent(student));
    }

    /**
     * 修改学生
     */

    @PutMapping
    public Result edit(@RequestBody Student student)
    {
        return Result.success(studentService.updateStudent(student));
    }

    /**
     * 删除学生
     */

	@DeleteMapping("/{sids}")
    public Result remove(@PathVariable Long[] sids)
    {
        return Result.success(studentService.deleteStudentBySids(sids));
    }
}
